<template>
  <div class="news-container">
    <div class="news-header">
      <div class="news-tabs">
        <span
          v-for="(tab, index) in tabs"
          :key="index"
          :class="['news-tab', { active: activeTab === index }]"
          @click="activeTab = index"
        >
          {{ tab }}
        </span>
      </div>
      <div class="more-link">
        <router-link to="/news">查看更多 ></router-link>
      </div>
    </div>

    <div class="news-content">
      <div class="news-image">
        <el-carousel height="200px" indicator-position="outside">
          <el-carousel-item v-for="(item, index) in carouselItems" :key="index">
            <el-image :src="item.image" fit="cover" style="width: 100%; height: 100%"></el-image>
          </el-carousel-item>
        </el-carousel>
      </div>

      <div class="news-list">
        <div v-for="(news, index) in newsList" :key="index" class="news-item">
          <div class="news-title">
            {{ news.title }}
          </div>
          <div class="news-date">{{ news.date }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import news1 from '@/assets/new1.jpg'
import news2 from '@/assets/new2.jpg'
import news3 from '@/assets/new3.jpg'

export default {
  name: 'NewsList',
  data() {
    return {
      activeTab: 0,
      tabs: ['通知公告', '行业资讯', '招标动态'],
      carouselItems: [
        { image: news1 },
        { image: news2 },
        { image: news3 },
      ],
      newsList: [
        { title: '2023年03月01日体育器材采购(冰雪)项目成交公告，66海牛产品成交', date: '2023-03-10' },
        { title: '2023年03月01日体育器材采购(冰雪)项目成交公告，66海牛产品成交', date: '2023-03-10' },
        { title: '2023年03月01日体育器材采购(冰雪)项目成交公告，66海牛产品成交', date: '2023-03-10' },
        { title: '2023年03月01日体育器材采购(冰雪)项目成交公告，66海牛产品成交', date: '2023-03-10' },
        { title: '2023年03月01日体育器材采购(冰雪)项目成交公告，66海牛产品成交', date: '2023-03-10' },
        { title: '2023年03月01日体育器材采购(冰雪)项目成交公告，66海牛产品成交', date: '2023-03-10' }
      ]
    }
  }
}
</script>

<style scoped>
.news-container {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
}

.news-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

.news-tabs {
  display: flex;
}

.news-tab {
  padding: 10px 20px;
  cursor: pointer;
  position: relative;
  color: #333;
}

.news-tab.active {
  color: #409eff;
  font-weight: bold;
}

.news-tab.active::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 20%;
  width: 60%;
  height: 3px;
  background-color: #409eff;
}

.more-link a {
  color: #409eff;
  text-decoration: none;
  font-size: 14px;
}

.news-content {
  display: flex;
  gap: 20px;
}

.news-image {
  flex: 1;
}

.news-list {
  flex: 2;
}

.news-item {
  display: flex;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid #f0f0f0;
}

.news-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.news-date {
  color: #999;
  font-size: 14px;
}
</style>
